<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录日期">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:energyProject:export']">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="energyProjectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目Id" align="center" prop="energyId" v-if="true"/>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="总制冷量" align="center" prop="totalCold" />
      <el-table-column label="总耗电量" align="center" prop="totalKwh" />
      <el-table-column label="总COP" align="center" prop="totalCop" />
      <el-table-column label="总散热量" align="center" prop="totalHeat" />
      <el-table-column label="目标COP" align="center" prop="targetCop" />
      <el-table-column label="记录日期" align="center" prop="createTime" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listEnergyProject, getEnergyProject, delEnergyProject, addEnergyProject, updateEnergyProject } from "@/api/system/energyProject";

export default {
  name: "EnergyProject",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 各项目每日能效表格数据
      energyProjectList: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询各项目每日能效列表 */
    getList() {
      this.loading = true;
      listEnergyProject(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.energyProjectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.energyId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/energyProject/export', {
        ...this.queryParams
      }, `energyProject_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
